mp_grid_create

语法:

mp_grid_create(left, top, hcells, vcells, cellwidth, cellheight):


参数 描述
left Starting x coordinate of the mp_grid in the room
top Starting y coordinate of the mp_grid in the room
hcells Number of horizontal cells that the mp_grid will contain
vcells Number of vertical cells that the mp_grid will contain
cellwidth The width (in pixels) of each individual cell of the mp_grid
cellheight The height (in pixels) of each individual cell of the mp_grid


Returns: Real.


描述

With this function you can create an mp_grid for the motion planning functions. It returns an index that must be used in all other mp_grid function calls. The x and y coordinates indicate the position of the top-left corner of the grid, hcells and vcells indicate the number of horizontal and vertical cells to be created within the grid, and cell width and cell height indicate the size of the cells in pixels. You can create and maintain multiple grid structures at the same moment if you need them for different things, but be aware that these are complex functions and the more you use and the higher the cell resolution then the slower your game could be.


例如:

global.grid = mp_grid_create(0, 0, room_width / 32, room_height /32, 32, 32)

The above code creates a global variable "grid", then generates an mp_grid and assigns its index (id) to that variable for use in all further mp_grid function calls. The grid covers the room, with a cell resolution of 32x32 pixels. This means that, for example, in a room that is 640x480, the grid would contain 300 cells: 20 horizontal cells (640 / 32) multiplied by 15 vertical cells (480 /32) gives 300 cells